﻿//-----------------------------------------------------------------------
// <copyright>
//     Copyright (c) Artur Mustafin. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using Expressions.Compiler.Interfaces;
using System.Collections.Generic;
using Expressions.Compiler;
using Excel.Expressions.Interfaces;

namespace Excel.Expressions.Compiler
{
    internal class Assignment__ : CellExpression__
    {
        private readonly CellReference _reference;
        private readonly CellExpression _expression;
        private readonly string _text;

        public Assignment__(CellExpression__ reference, CellExpression__ expression, string text)
        {
            _text = text;
            _reference = reference as CellReference__;
            _expression = expression;
            Add(_reference);
            Add(_expression);
        }

        public CellExpression__ Expression
        {
            get
            {
                return _expression;
            }
        }

        public string Text
        {
            get
            {
                return _text;
            }
        }

        public CellReference CellReference
        {
            get
            {
                return _reference;
            }
        }

        public override double Eval()
        {
            return _expression;
        }

#if DEBUG
        public override string ToString()
        {
            return string.Format("{0}={1}", _reference.Cell.Name, _expression);
        }
#endif
    }
}
